<script setup>
import PageHeader from "@/views/Common/PageHeader.vue";
import { useUserStore } from '@/stores/user.js';
import { useRouter } from 'vue-router';
import { onMounted } from 'vue';

const userStore = useUserStore();
const router = useRouter();

// 检查用户是否为管理员
onMounted(() => {
  if (!userStore.isLogin || !userStore.isAdmin) {
    router.push('/homePage');
  }
});
</script>

<template>
  <div class="admin-layout">
    <div>
      <PageHeader></PageHeader>
    </div>

    <!-- Logo区域 -->
    <div class="logo-section">
      <div class="logo-container">
        <img
            class="logo"
            src="@/assets/SAS-logo.png"
            alt="SAS系统logo"
        >
        <!-- 新增管理员系统标题 -->
        <h1 class="system-title">管理系统 <span class="admin-text">| 管理员专区</span></h1>
      </div>
    </div>

    <!-- 主要内容区域 -->
    <div class="main-content">
      <!-- 侧边导航 -->
      <aside class="sidebar">
        <!-- 新增侧边栏标题 -->
        <div class="sidebar-title">管理员功能菜单</div>
        <el-menu
            class="admin-menu"
            router
            :default-active="$route.path"
            background-color="#fafbfc"
            text-color="#2c3e50"
            active-text-color="#409EFF"
        >
          <el-menu-item index="/admin/dashboard" class="menu-item">
            <!-- 菜单前添加管理员小标识 -->
            <span class="menu-admin-mark">管</span>
            <span class="menu-text">仪表盘</span>
          </el-menu-item>
          <el-menu-item index="/admin/users" class="menu-item">
            <span class="menu-admin-mark">管</span>
            <span class="menu-text">用户管理</span>
          </el-menu-item>
          <el-menu-item index="/admin/finance/review" class="menu-item">
            <!-- 菜单前添加管理员小标识 -->
            <span class="menu-admin-mark">管</span>
            <span class="menu-text">审核融资申请</span>
          </el-menu-item>
          <el-menu-item index="/admin/goods" class="menu-item">
            <span class="menu-admin-mark">管</span>
            <span class="menu-text">商品管理</span>
          </el-menu-item>
        </el-menu>
      </aside>

      <!-- 页面内容区域 -->
      <main class="content-area">
        <!-- 新增内容区顶部提示 -->
        <div class="content-header" v-if="$route.name === 'GoodsManagement'">
          <h2>商品管理</h2>
          <p class="admin-desc">您拥有审核、管理所有商品的权限</p>
        </div>
        <div class="content-header" v-else-if="$route.name === 'UserManagement'">
          <h2>用户管理</h2>
          <p class="admin-desc">您拥有管理所有用户的权限</p>
        </div>
        <div class="content-header" v-else-if="$route.name === 'FinanceReview'">
          <h2>审核融资申请</h2>
          <p class="admin-desc">您拥有审核、管理所有融资申请的权限</p>
        </div>
        <div class="content-header" v-else>
          <h2>管理员操作中心</h2>
          <p class="admin-desc">您拥有系统管理的全部权限</p>
        </div>
        <router-view></router-view>
      </main>
    </div>
  </div>
</template>

<style scoped lang="less">
.admin-layout {
  min-height: 100vh;
  background: linear-gradient(135deg, #f5f7fa 0%, #f3f6f8 100%);
  display: flex;
  flex-direction: column;
  /* 新增管理员主题色 */
  --admin-color: #c92027;
  --admin-bg: #fff5f5;
}

.admin-header-content {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 20px;
  height: 60px;
}

/* 新增管理员徽章 */
.admin-badge {
  background-color: var(--admin-bg);
  color: var(--admin-color);
  font-weight: 600;
  padding: 4px 12px;
  border-radius: 4px;
  border-left: 3px solid var(--admin-color);
  font-size: 14px;
}

/* Logo区域样式调整 */
.logo-section {
  background: #ffffff;
  padding: 15px 0;
  border-bottom: 1px solid #eaeef2;
}

.logo-container {
  display: flex;
  align-items: center;
  margin-left: 40px;
}

.logo {
  height: 50px;
  width: auto;
  transition: transform 0.3s ease;

  &:hover {
    transform: scale(1.02);
  }
}

/* 新增系统标题样式 */
.system-title {
  margin: 0 0 0 20px;
  font-size: 18px;
  color: #333;
  font-weight: 600;
}

.admin-text {
  color: var(--admin-color);
  font-size: 14px;
  margin-left: 10px;
  font-weight: normal;
}

/* 主要内容区域调整 */
.main-content {
  display: flex;
  flex: 1;
  max-width: 1800px;
  margin: 0 auto;
  padding: 24px;
  gap: 24px;
  width: 100%;
  box-sizing: border-box;
}

/* 侧边栏增强 */
.sidebar {
  flex-shrink: 0;
  width: 240px;
  background-color: white;
  border-radius: 8px;
  padding: 15px;
  margin-bottom: 10px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.08);
  overflow: hidden;
}

/* 新增侧边栏标题 */
.sidebar-title {
  padding: 16px 20px;
  background-color: var(--admin-bg);
  color: var(--admin-color);
  font-weight: 600;
  font-size: 15px;
  border-bottom: 1px solid #f0e6e6;
}

.admin-menu {
  border: none;
  border-radius: 0;
  box-shadow: none;
  padding: 16px 8px;
}

.menu-item {
  margin: 4px 0;
  height: 44px;
  border-radius: 8px;
  transition: all 0.3s ease;

  &:hover {
    background-color: var(--admin-bg);
    transform: translateX(4px);
  }

  &.is-active {
    background-color: var(--admin-bg);
    color: var(--admin-color);
    box-shadow: 0 2px 8px rgba(201, 32, 39, 0.15);

    .menu-text {
      color: var(--admin-color);
      font-weight: 600;
    }
  }
}

/* 新增菜单前的管理员标识 */
.menu-admin-mark {
  display: inline-block;
  width: 20px;
  height: 20px;
  line-height: 20px;
  text-align: center;
  background-color: var(--admin-color);
  color: white;
  border-radius: 50%;
  font-size: 12px;
  margin-right: 8px;
}

.menu-text {
  font-size: 14px;
  font-weight: 500;
  letter-spacing: 0.5px;
}

/* 内容区域增强 */
.content-area {
  flex: 1;
  min-width: 0;
  background: white;
  border-radius: 8px;
  padding: 15px;
  margin-bottom: 10px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.06);
  min-height: 600px;
}

/* 新增内容区头部 */
.content-header {
  margin-bottom: 24px;
  padding-bottom: 16px;
  border-bottom: 1px solid #f0f0f0;
}

.content-header h2 {
  margin: 0 0 8px 0;
  color: #333;
  font-size: 20px;
}

.admin-desc {
  margin: 0;
  color: #666;
  font-size: 14px;
  background-color: var(--admin-bg);
  display: inline-block;
  padding: 4px 12px;
  border-radius: 4px;
}

/* 响应式设计调整 */
@media (max-width: 1200px) {
  .main-content {
    padding: 16px;
    gap: 16px;
  }

  .sidebar {
    width: 200px;
  }

  .content-area {
    padding: 20px;
  }
}

@media (max-width: 768px) {
  .main-content {
    flex-direction: column;
    padding: 12px;
  }

  .sidebar {
    width: 100%;
    margin-bottom: 16px;

    .admin-menu {
      display: flex;
      padding: 8px;

      .menu-item {
        flex: 1;
        margin: 0 4px;
        text-align: center;
      }
    }
  }

  .logo-container {
    margin-left: 20px;
  }

  .logo {
    height: 40px;
  }

  .system-title {
    font-size: 16px;
    margin-left: 10px;
  }

  .content-area {
    min-height: 400px;
    padding: 16px;
  }
}

/* 原有动画和滚动条样式保持不变 */
.admin-layout {
  animation: fadeIn 0.6s ease-in-out;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

:deep(.el-menu) {
  &::-webkit-scrollbar {
    width: 6px;
  }

  &::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 3px;
  }

  &::-webkit-scrollbar-thumb {
    background: #c1c1c1;
    border-radius: 3px;

    &:hover {
      background: #a8a8a8;
    }
  }
}

.admin-layout {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
}

.menu-item {
  position: relative;
  overflow: hidden;

  &::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    height: 100%;
    width: 3px;
    background: var(--admin-color);
    transform: scaleY(0);
    transition: transform 0.3s ease;
  }

  &:hover::before {
    transform: scaleY(1);
  }

  &.is-active::before {
    transform: scaleY(1);
  }
}
</style>
